<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
		StringBuffer errorString=new StringBuffer("");
		if (request.getParameter("tk") != null)
		{
			errorString.append("标题不能为空！\\n");
		}
		if (request.getParameter("ck") != null)
		{
			errorString.append("内容不能为空！ \\n");
		}
		if (request.getParameter("sl") != null)
		{
			errorString.append("附件应该小于10M！ \\n");
		}
		if (request.getParameter("f") != null)
		{
			errorString.append("上次附件格式不正确！\\n ");
		}
		if (request.getParameter("un") != null)
		{
			errorString.append("添加失败！ \\n");
		}	
		if (request.getParameter("exs") != null)
		{
			errorString.append("已存在相同标题知识！\\n");
		}
		if (request.getParameter("ok") != null)
		{
			errorString.append("添加成功！\\n");
		}
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>添加知识</title>
		<link href="css/gl/tjzs.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src='dwr/engine.js'>
</script>
		<script type="text/javascript" src='dwr/util.js'>
</script>
<script type="text/javascript" src="script/jquery/jquery-1.5.1.min.js" ></script>
<script type="text/javascript" src='dwr/interface/ZhiShiDwr.js'>
</script>
<script type="text/javascript">
//添加知识
function addToGao(){
	var title = $("#title").val();
	var content = $("#content").val();
	var imgfile = $("#imgfile").val();
	var kind = $("#kind").val();
	if(kind==null){
		alert("请选择分类！");
		return false;
	}
	if(kind.length<1){
		alert("请选择分类！");
		return false;
	}
	if(title.length<1){
		alert("标题不能为空！");
		return false;
	}else if(title.length>100){
		alert("标题字数应小于100！");
		return false;
	}
    if(content.length>5000){
		alert("内容字数应小于5000！");
		return false;
	}

	if(imgfile.length>3){//说明上传了文件
	    if(imgfile.lastIndexOf(".")==-1)
	    {
	         alert("上传附件格式不正确！");
       		 return false;
	    }
	 }
	document.addNotice.submit();
}
function error()
{ 
	if("<%=errorString.toString()%>".length>0)
	{
	 alert("<%=errorString.toString()%>");
	}
}
$(function() {
	error();
	GetCategory();
});
//get the konwledge category
function GetCategory(){
	ZhiShiDwr.GetCategory(function(data){
		$("#kind").find("option").remove();
		for(var i=0;i<data.length;i++){
	       $("#kind").append("<option value='"+data[i].id+"'>"+data[i].name+"</option>"); 
		}
	});
}
</script>
	</head>

	<body>
		<form name="addNotice" method="post" enctype="multipart/form-data"
			action="gl/addZhiShi.do">
			<div id="page_all">
				<jsp:include page="title.jsp" flush="true">
					<jsp:param name="jspName" value="zskModuleOpt" />
				</jsp:include>
				<div id="main">
					<div id="tgleft">
						<jsp:include page="zskleft.jsp" flush="true">
							<jsp:param name="jspName" value="tjzsModuleOpt" />
						</jsp:include>
					</div>
					<div id="tgmain">
						<table id="addnotice" cellpadding="0" cellspacing="0">
							<tr>
								<td class="ftd">
									分&nbsp;类:
								</td>
								<td>
									<select id="kind" name="kind">
									</select>
								</td>
							</tr>
							<tr>
								<td class="ftd">
									标&nbsp;题:
								</td>
								<td>
									<input id="title" name="title" maxlength="100">
								</td>
							</tr>
							<tr>
								<td class="ftd" style="vertical-align: top;">
									内&nbsp;容:
								</td>
								<td>
									<textarea id="content" name="content" onkeyup="this.value = this.value.substring(0, 4999);"></textarea>
								</td>
							</tr>
							<tr>
								<td class="ftd">
									上传附件:
								</td>
								<td>
									<input id="imgfile" name="imgfile" type="file" style="height:21px;">
								</td>
							</tr>
							<tr>
								<td colspan="2" style="text-align:center;">
									<img alt="" style="cursor:pointer;" src="img/gl/addbtn.jpg" onclick="addToGao()" />
								</td>
							</tr>
						</table>
					</div>

				</div>
				<div id="footer">
					<jsp:include page="footer.jsp" flush="true"></jsp:include>
				</div>
			</div>
		</form>
	</body>
</html>
